<?php

namespace App\CustHub\Controller\Admin;

use App\CustHub\Request\ChTransferRecordsRequest;
use App\CustHub\Service\ChTransferRecordService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\PostMapping;
use Hyperf\HttpServer\Annotation\PutMapping;
use Mine\Annotation\Auth;
use Mine\Annotation\OperationLog;
use Mine\Annotation\Permission;
use Mine\Annotation\RemoteState;
use Mine\MineController;
use Psr\Http\Message\ResponseInterface;

#[Controller(prefix: "custhub/chTransferRecords"), Auth]
class ChTransferRecordController extends MineController
{
    /**
     * 业务处理服务
     * ChTransferRecordsService
     */
    #[Inject]
    protected ChTransferRecordService $service;


    /**
     * 列表
     * @return ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[GetMapping("index"), Permission("custhub:chTransferRecords, custhub:chTransferRecords:index")]
    public function index(): ResponseInterface
    {
        $data = $this->request->all();
        $data['orderBy'] = 'created_at';
        $data['orderType'] = 'desc';
        return $this->success($this->service->getPageList($data));
    }

    /**
     * 更新
     * @param int $id
     * @param ChTransferRecordsRequest $request
     * @return ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PutMapping("update/{id}"), Permission("custhub:chTransferRecords:update"), OperationLog]
    public function update(int $id, ChTransferRecordsRequest $request): ResponseInterface
    {
        return $this->service->update($id, $request->all()) ? $this->success() : $this->error();
    }

    /**
     * 读取数据
     * @param int $id
     * @return ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[GetMapping("read/{id}"), Permission("custhub:chTransferRecords:read")]
    public function read(int $id): ResponseInterface
    {
        return $this->success($this->service->read($id));
    }


    /**
     * 远程万能通用列表接口
     * @return ResponseInterface
     */
    #[PostMapping("remote"), RemoteState(true)]
    public function remote(): ResponseInterface
    {
        return $this->success($this->service->getRemoteList($this->request->all()));
    }
}